from django.db import models


class Team(models.Model):

    name = models.CharField(max_length=100, verbose_name='球队名', help_text='球队名')

    def __str__(self):
        return self.name
    


    @classmethod
    def get_or_create(cls,name):
        obj = cls.objects.filter(name=name).first()
        if obj:
            return obj
        else:
            obj = cls(name=name)
            obj.save()
            return obj
    
    class Meta:
        verbose_name_plural = verbose_name = '球队'

# Create your models here.
class Player(models.Model):

    season = models.CharField(max_length=100, help_text='季度',verbose_name='季度')
    name = models.CharField(max_length=100, help_text='名称',verbose_name='名称')
    player_id = models.CharField(max_length=100,help_text='player_id')
    team = models.ForeignKey(Team, on_delete=models.CASCADE,verbose_name='球队',help_text='球队')
    games = models.PositiveIntegerField(help_text='比赛场次',verbose_name='比赛场次')
    mins = models.PositiveIntegerField(help_text='出场时间',verbose_name='出场时间')
    points = models.PositiveIntegerField(help_text='得分',verbose_name='得分')
    rebs = models.PositiveIntegerField(help_text='篮板',verbose_name='篮板')
    assists = models.PositiveIntegerField(help_text='助攻',verbose_name='助攻')
    steals = models.PositiveIntegerField(help_text='抢断',verbose_name='抢断')
    blocks = models.PositiveIntegerField(help_text='盖帽',verbose_name='盖帽')
    fgpct = models.FloatField(help_text='投篮命中率',verbose_name='投篮命中率')
    tpm = models.PositiveIntegerField(help_text='三分命中数',verbose_name='三分命中数')
    tppct = models.FloatField(help_text='三分命中率',verbose_name='三分命中率')
    ftpct = models.FloatField(help_text='罚球命中率',verbose_name='罚球命中率')

    class Meta:
        verbose_name_plural = verbose_name = '球员'